class Solution {
public:
  // 利用unordered_map查找target-num[i]是否在哈希表中
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> hash;  // <数值,下标>
        //vector<int> res(2);
        for(int i = 0; i < nums.size(); ++i){
            if(hash.find(target-nums[i]) != hash.end()){
             /*   
                res[0] = hash[target-nums[i]];
                res[1] = i;
                return res;
             */
                return {hash[target-nums[i]], i};   
            }
            //hash[nums[i]] = i;
            hash.insert(pair<int, int>(nums[i], i));
        }
        return {};
    }
};